var app = getApp()

Page({
    data:{
        activity:{},
        tasks : [],
        options : {},
        doingTask : false,
        metas : []
    },
    onLoad:function(options){
        var that = this;
        this.setData({
            options:options
        });
        var id = options.id;
        if(!id) id = 1;

        app.showLoading();

        //获取活动详情
        app.request("scenicespot/activity/"+id, "GET", null, function(res){
            that.setData({
                activity : res.result
            });
        });

        //获取任务卡列表
        app.request("taskcard/avtivity/"+id, "GET", null, function(res){
            that.setData({
                tasks : res.result
            });
        });

        //检测是否有正在执行的任务
        app.request("task/activity/process/"+id, "GET", null, function(res){
            that.setData({ 
                doingTask : true
            });
            app.closeLoading();
        }, function(res){
            that.setData({
                doingTask : false
            });
            app.closeLoading();
        });
    },
    join : function(event){
        var activityid = event.currentTarget.dataset.hi;
        wx.navigateTo({
            url: '../task/task?id='+activityid
        })
    },
    preview_map : function(event){
        var url = event.currentTarget.dataset.mapurl;
        wx.previewImage({
        current: url, // 当前显示图片的http链接
        urls: [url] // 需要预览的图片http链接列表
        })
    },
    onTaskClick : function(event){
      //return;
        var id = event.currentTarget.dataset.taskid;
        wx.navigateTo({
            url: '../taskview/taskview?id='+id
        })
    },
    view_address_map : function(){
        var activity = this.data.activity;
        app.openMap(activity.mapCoordinates.split(",")[0], 
            activity.mapCoordinates.split(",")[1],
            activity.shortName, activity.address);
    }
})